package com.closer.server.mapper.user;

import com.closer.server.biz.user.entity.UserRole;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.query.QueryWrapper;

/**
 * 用户拥有角色 映射层。
 *
 * @author closer
 */
public interface UserRoleMapper extends BaseMapper<UserRole> {

    /**
     * 根据用户id删除
     * @param id 用户id
     */
    default void deleteByUserId(Long id) {
        var queryWrapper = QueryWrapper.create().eq("user_id",id);
        deleteByQuery(queryWrapper);
    }

    default int updateByAdmin(Long userId, Long roleId) {
        var queryWrapper = QueryWrapper.create()
                .eq("user_id",userId);
        var userRole =selectOneByQuery(queryWrapper);
        userRole.setRoleId(roleId);
        return update(userRole);
    }
}
